﻿using System;
using System.Web;

namespace ECommerce.Web.Services.Cookies
{
    public class CookieContainer : ICookieContainer
    {
        public void Set(string key, string value, DateTime expires)
        {
            if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); }
            
            var cookie = new HttpCookie(key);

            cookie.Value = value;
            cookie.Expires = expires;

            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        public string Get(string key)
        {
            if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); }
            
            HttpCookie cookie = HttpContext.Current.Request.Cookies[key];

            if (cookie == null) { return String.Empty; }

            return cookie.Value;
        }
    }
}
